package com.cjh.utils;

import javax.servlet.http.HttpServletRequest;

public class RequestUtils {

    /**
     * 获取请求用户IP.
     * @param requset
     * @return ip
     */
    public static String getIp(HttpServletRequest requset){
        String ip = requset.getHeader("x-forwarded-for");
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
            ip = requset.getHeader("Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
            ip = requset.getHeader("WL-Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
            ip = requset.getRemoteAddr();
        }
        ip = ip.equals("0:0:0:0:0:0:0:1")?"127.0.0.1":ip;
        return ip;
    }

}